﻿
(function ($) {
    $("#Filter1")
        .advansedFilter({
            colcount: 3,
            //store: true,
            //inhash: true,
            maxfilters: -1,
            anykey: true,
            anykeytimeout: 500,
            help: "text <span class='filter-example'>filter</span>&nbsp;text",
            sorters: [
              {id: "by-name", title: "по названию", sortOrder: "descending", def: true},
              {id: "by-create", title: "по дате старта", sortOrder: "descending" },
              {id: "by-deadline", title: "по дате окончания" },
              {id: "by-priority", title: "по приоритету" },
              {id: "by-cnt-subtasks", title: "по кол-ву подзадач" },
              {id: "by-cnt-responsibles", title: "по кол-ву исполнителей" },
              {id: "by-responsible", title: "по исполнителю", sortOrder: "descending" }
            ],
            filters: [
                {
                    type: "combobox",
                    id: "selected-somecombobox-value1",
                    title: "Value 1",
                    filtertitle: "Value",
                    group: "Варианты",
                    groupby: "selected-somecombobox-value",
                    options: [
                    {value: "value1", classname: "class1", title: "1", def: true},
                    {value: "value2", classname: "class2", title: "2"},
                    {value: "value3", classname: "class3", title: "3"}
                  ],
                    hashmask: "combobox/{0}"
                },
                {
                    type: "combobox",
                    id: "selected-somecombobox-value-2",
                    title: "Value 2",
                    filtertitle: "Value",
                    group: "Варианты",
                    groupby: "selected-somecombobox-value",
                    options: [
                    {value: "value1", classname: "class1", title: "1"},
                    {value: "value2", classname: "class2", title: "2", def: true},
                    {value: "value3", classname: "class3", title: "3"}
                  ],
                    hashmask: "combobox/{0}"
                },
                {
                    type: "combobox",
                    id: "selected-somecombobox-value-3",
                    title: "Value 3",
                    filtertitle: "Value",
                    group: "Варианты",
                    groupby: "selected-somecombobox-value",
                    options: [
                    {value: "value1", classname: "class1", title: "1"},
                    {value: "value2", classname: "class2", title: "2" },
                    {value: "value3", classname: "class3", title: "3", def: true }
                  ],
                    hashmask: "combobox/{0}"
                },
                {
                    type: "combobox",
                    id: "selected-somecombobox11",
                    title: "Список1",
                    defaulttitle: "Выберите",
                    group: "Прочие",
                    multiple: true,
                    options: [
                        {value: "value1", classname: "class1", title: "Core & Controls"},
                        {value: "value2", classname: "class2", title: "Value 2"},
                        {value: "value3", classname: "class3", title: "Value 3"},
                        {value: "<script>alert('1'+'2')<\/script>", classname: "class4", title: "<script>alert('1'+'2')<\/script>"},
                        {value: "value5", classname: "class5", title: "Value 5"},
                        {value: "value6", classname: "class6", title: "Value 6"},
                        {value: "value7", classname: "class7", title: "Value 7"},
                        {value: "value8", classname: "class8", title: "Value 8"},
                        {value: "value9", classname: "class9", title: "Value 9"}
                    ],
                    //params: {value : "value9"},
                    hashmask: "combobox/{0}"
                }
            ]
        })
        .bind("updatefilter", function(evt, $container, filterid, selectedfilters) {
            console.log("updatefilter: ", filterid, "\n", selectedfilters);
        })
        //.bind("resetallfilters", function (evt, $container, filterid, selectedfilters) {
        //    console.log("resetallfilters: ", filterid, "\n", selectedfilters);
        //})
        //.bind("setfilter", function (evt, $container, filter, params, selectedfilters) {
        //    console.log(" + filter: ", filter.id, " ", params, "\n", selectedfilters);
        //})
        //.bind("resetfilter", function (evt, $container, filter, selectedfilters) {
        //    console.log(" - filter: ", filter.id, " ", "\n", selectedfilters);
        //})
        .advansedFilter("sort", false);

    $("input.input-datepicker:first").datepicker();

    $("button.upload-file1").click(function (evt) {
        $.tlDialog("jqTemplateMyDialog1", {
            tmplData: {userName: "Dmitri Frolov"},
            buttons: [
                {
                    text: "Delete all items",
                    click: function (evt) {
                        alert("Delete all items");
                    }
                }
            ]
        });
    });

    $("button.upload-file2").click(function (evt) {
        $.tlDialog("jqTemplateMyDialog2", {
            tmplData: { userName: "Dmitri Frolov" },
            buttons: [
                {
                    text: "Delete all items",
                    click: function (evt) {
                        alert("Delete all items");
                    }
                }
            ]
        });
    });

    $("button.action-group-item.edit").click(function (evt) {
        console.log("edit user");
    });
    $("button.action-group-item.delete").click(function (evt) {
        console.log("delete user");
    });
    $("button.action-group-item.connect-via-jabber").click(function (evt) {
        console.log("connect via jabber to user");
    });

    $("button.remove-some-user-group-item.edit").click(function (evt) {
        console.log("edit users");
    });
    $("button.remove-some-user-group-item.delete").click(function (evt) {
        console.log("delete users");
    });
    $("button.remove-some-user-group-item.connect-to-user").click(function (evt) {
        console.log("connect via jabber to users");
    });
})(jQuery);
